using UnityEngine;
using Weapons.Components.ComponentData;
using Weapons.Components.ComponentData.AttackData;

namespace Weapons.Components
{
    public abstract class WeaponComponent : MonoBehaviour
    {
        //TODO:��ʱ����
        //protected AnimationEventHandler EventHandler =>newWeapon.EventHandler;


        protected AnimationEventHandler eventHandler;

        protected bool isAttackActive;

        protected NewWeapon newWeapon;

        protected Core Core => newWeapon.Core;

        protected virtual void Awake()
        {
            newWeapon = GetComponent<NewWeapon>();

            eventHandler = GetComponentInChildren(typeof(AnimationEventHandler)) as AnimationEventHandler;
        }

        protected virtual void Start()
        {
            newWeapon.OnEnter += HandleEnter;
            newWeapon.OnExit += HandleExit;
        }


        protected virtual void OnDestroy()
        {
            newWeapon.OnEnter -= HandleEnter;
            newWeapon.OnExit -= HandleExit;
        }

        public virtual void Init()
        {
        }


        protected virtual void HandleEnter()
        {
            isAttackActive = true;
        }

        protected virtual void HandleExit()
        {
            isAttackActive = false;
        }
    }

    //possible bug point
    //������������һ���Լ��������ռ䵼������������������ͨ��vsstudio�Զ�������ɣ������������ۣ����������ռ��Ǻ�������ȥ�ģ�һ��Bug��
    //learn point:�������ʹ��
    public abstract class WeaponComponent<T1, T2> : WeaponComponent where T1 : ComponentData<T2> where T2 : AttackData
    {
        protected T2 currentAttackData;
        protected T1 data;

        public override void Init()
        {
            base.Init();

            data = newWeapon.Data.GetData<T1>();
        }

        protected override void HandleEnter()
        {
            base.HandleEnter();

            currentAttackData = data.AttackData[newWeapon.CurrentAttackCounter];
        }
    }
}